<%= form_for @changeset, @action, [multipart: true, class: "ui form"], fn f -> %>
  <div class="four fields">
    <div class="field required <%= AdminHelpers.error_class(f, :name) %>">
      <%= label(f, :name, "Name") %>
      <%= text_input(f, :name, placeholder: "The Changelog") %>
      <%= AdminHelpers.error_message(f, :name) %>
    </div>

    <div class="field required <%= AdminHelpers.error_class(f, :status) %>">
      <%= label(f, :status) %>
      <%= select(f, :status, status_options(), class: "ui fluid dropdown") %>
    </div>

    <div class="field required <%= AdminHelpers.error_class(f, :slug) %>">
      <%= label(f, :slug) %>
      <%= text_input(f, :slug, placeholder: "tcl", readonly: AdminHelpers.is_persisted(f.data)) %>
      <%= AdminHelpers.error_message(f, :slug) %>
    </div>

    <div class="field required <%= AdminHelpers.error_class(f, :position) %>">
      <%= label(f, :position) %>
      <%= select(f, :position, position_options(), class: "ui fluid dropdown") %>
    </div>
  </div>

  <div class="three fields">
    

    <div class="field <%= AdminHelpers.error_class(f, :vanity_domain) %>">
      <%= label(f, :vanity_domain, "Vanity Domain") %>
      <%= text_input(f, :vanity_domain, placeholder: "https://changelog.fm") %>
      <%= AdminHelpers.error_message(f, :vanity_domain) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :twitter_handle) %>">
      <%= label(f, :twitter_handle, "On Twitter") %>
      <%= text_input(f, :twitter_handle, placeholder: "gracehopper") %>
      <%= AdminHelpers.error_message(f, :twitter_handle) %>
    </div>

    <div class="field <%= AdminHelpers.error_class(f, :mastodon_handle) %>">
      <%= label(f, :mastodon_handle, "On Mastodon") %>
      <%= text_input(f, :mastodon_handle, placeholder: "changelog@changelog.social") %>
    </div>
  </div>

  <div class="two fields">
    <div class="fourteen wide field">
      <label for="cover">
        Cover
        <%= AdminHelpers.help_icon("Ideal size is 3000px by 3000px") %>
      </label>
      <%= AdminHelpers.error_message(f, :cover) %>
      <%= file_input(f, :cover) %>
    </div>

    <div class="two wide field">
      <img src="<%= cover_url(f.data, :small) %>" height=66>
    </div>
  </div>

  <div class="required field">
    <%= label(f, :hosts) %>

    <div class="ui middle aligned selection list js-podcast_hosts">
      <%= inputs_for f, :podcast_hosts, fn i -> %>
        <div class="item <%= if AdminHelpers.is_persisted(i.data), do: "persisted" %>">
          <%= hidden_input i, :person_id %>
          <%= hidden_input i, :position, class: "js-position" %>
          <img class="ui avatar image" src="<%= ChangelogWeb.PersonView.avatar_url(i.data.person) %>">

          <div class="content">
            <div class="header"><%= i.data.person.name %> (@<%= i.data.person.handle %>)</div>
          </div>

          <div class="right floated content">
          <%= if i.data.retired do %>
            <div class="ui tiny icon negative button js-retire">
              <i class="microphone slash icon"></i>
              <%= hidden_input(i, :retired) %>
            </div>
          <% else %>
            <div class="ui tiny icon positive button js-retire">
              <i class="microphone icon"></i>
              <%= hidden_input(i, :retired) %>
            </div>
          <% end %>

            <div class="ui tiny icon button js-remove">
              <i class="remove icon"></i>
              <%= hidden_input(i, :delete) %>
            </div>
          </div>
        </div>
      <% end %>
    </div>

    <div class="ui search">
      <div class="ui left icon input">
        <input class="prompt" type="text" placeholder="Add a Host">
        <i class="user icon"></i>
      </div>
    </div>
  </div>

  <div class="field">
    <%= label(f, :topics) %>

    <div class="ui horizontal selection list js-podcast_topics">
      <%= inputs_for f, :podcast_topics, fn i -> %>
        <% topic = AdminHelpers.load_from_form(i, Topic, :topic) %>
        <div class="item <%= if AdminHelpers.is_persisted(i.data), do: "persisted" %>">
          <%= hidden_input i, :topic_id %>
          <%= hidden_input i, :position, class: "js-position" %>

          <div class="content">
            <a class="ui label">
              <%= topic.name %>
              <span class="js-remove">
                <i class="delete icon"></i>
                <%= hidden_input i, :delete %>
              </span>
            </a>
          </div>
        </div>
      <% end %>
    </div>

    <div class="ui search">
      <div class="ui left icon input">
        <input class="prompt" type="text" placeholder="Add a Topic">
        <i class="block layout icon"></i>
      </div>
    </div>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :schedule_note) %>">
    <%= label(f, :schedule_note) do %>
      Schedule Note <%= AdminHelpers.help_icon("Markdown supported.") %>
    <% end %>
    <%= text_input(f, :schedule_note, placeholder: "New show every Friday!") %>
    <%= AdminHelpers.error_message(f, :schedule_note) %>
  </div>

  <div class="inline field">
    <div class="ui toggle checkbox">
      <%= checkbox(f, :recorded_live, class: "hidden") %>
      <label>Recorded Live</label>
    </div>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :welcome) %>">
    <%= label(f, :welcome) do %>
      Welcome <%= AdminHelpers.help_icon("Only used on changelog.com landing pages.") %>
    <% end %>
    <%= textarea f, :welcome, placeholder: "Markdown enabled." %>
    <%= AdminHelpers.error_message(f, :welcome) %>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :description) %>">
    <%= label(f, :description) %>
    <%= textarea f, :description, placeholder: "Markdown enabled." %>
    <%= AdminHelpers.error_message(f, :description) %>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :extended_description) %>">
    <%= label(f, :extended_description) do %>
      Extended Description <%= AdminHelpers.help_icon("Only used in RSS for SEO.") %>
    <% end %>
    <%= textarea f, :extended_description %>
    <%= AdminHelpers.error_message(f, :extneded_description) %>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :keywords) %>">
    <%= label(f, :keywords) %>
    <%= text_input(f, :keywords, placeholder: "changelog, open source, software, development") %>
    <%= AdminHelpers.error_message(f, :keywords) %>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :apple_url) %>">
    <%= label(f, :apple_url, "Apple Podcasts URL") %>
    <%= text_input(f, :apple_url) %>
    <%= AdminHelpers.error_message(f, :apple_url) %>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :spotify_url) %>">
    <%= label(f, :spotify_url, "Spotify URL") %>
    <%= text_input(f, :spotify_url) %>
    <%= AdminHelpers.error_message(f, :spotify_url) %>
  </div>

  <div class="field <%= AdminHelpers.error_class(f, :riverside_url) %>">
    <%= label(f, :riverside_url, "Riverside URL") %>
    <%= text_input(f, :riverside_url) %>
    <%= AdminHelpers.error_message(f, :riverside_url) %>
  </div>

  <div class="ui hidden divider"></div>
  <div class="ui equal width stackable grid">
  <%= if !AdminHelpers.is_persisted(f.data) do %>
    <div class="column"><%= AdminHelpers.submit_button(:primary, "Create") %></div>
    <div class="column"><%= AdminHelpers.submit_button(:secondary, "Create and Close", AdminHelpers.next_param(@conn, ~p"/admin/podcasts")) %></div>
  <% else %>
    <div class="column"><%= AdminHelpers.submit_button(:primary, "Save", "edit") %></div>
    <div class="column"><%= AdminHelpers.submit_button(:secondary, "Save and Close", AdminHelpers.next_param(@conn)) %></div>
  <% end %>
    <div class="column"></div>
  </div>
<% end %>
